package bcryptTool

import (
	"errors"
	"golang.org/x/crypto/bcrypt"
)

// GetPwd 密码加密
func GetPwd(password string) string {
	encodePassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
	if err != nil {
		panic(errors.New("生成密码失败！"))
	}
	return string(encodePassword)
}

// ComparePwd pwd 是数据库密码 pwd2 是用户传递过来的密码
func ComparePwd(pwd, pwd2 string) {
	if bcrypt.CompareHashAndPassword([]byte(pwd), []byte(pwd2)) != nil {
		panic("登录失败，用户名或密码错误！")
	}
}
